import Item from 'antd-mobile/es/components/dropdown/item'
import React,{useState,useEffect} from 'react'
import { getHomeList } from '../../../components/api'
import {getEbook_author} from "../../../components/api"
import "../../public/public.css"
import All from "../../common/ebookTil/index"
import Wujie from "../home/wujie/index"
import Zuixin from "../../common/newAuthor"
import EbookTil from "../../common/ebookTil/index";
import Haizi from "../home/haizi/index"
import style from "../../common/newAuthor/new_author.module.css";
import { NavLink ,useParams} from 'react-router-dom'
const { all,authorImg } = style;

interface IP{
    introduc?: string,
    [propName:string]:any
}

interface IP2{
    introduc?: string,
    [propName:string]:any
}

// export interface IAuthor {
//   id: number,
//   name: string,
//   [propName: string]: any
// }

// export interface IAuthorList {
//   title?: string,
//   list?: IAuthor
// }


export default function Home() {
    const [Home, setHome] = useState<IP>({})
    const [Home2, setHome2] = useState<IP2>({})
    const [authorList, setEbook] = useState<any>([])
  const [qikan, setqikan] = useState<any>([])
  // console.log(qikan, "qikan");
  const [a,seta]=useState<any>([])

  
    
    const getBook =  async()=> {
        let res = await getEbook_author()
        // console.log(res,"erygrfg");
        setEbook(res.data[0])
      setqikan(res.data[1])
      seta(res.data[1].list[0])
        // console.log();
        

   }
    const getHome = () => {
        getHomeList().then(res => {
            // console.log(res,"12345");
            setHome(res.data)
            setHome2(res.data.content)

            // console.log(Home)
            
        })
    }
    // let til=qikan.title
  let b=a.id
  // console.log(b,"123id");
  

  
    useEffect(()=>{
        getHome()
        getBook()
        
    }, [])
    useEffect(() => {
        // console.log(qikan,"45");
        
    },[qikan]
    )
  return (
      <div>
          <div>
              <div className='int'>
                   <All title={ Home.introduce} > </All>  
              </div>
        <NavLink to={"/detail/"+Home2.id}>
          <div className='tianxia'>
              <img className='img' src={Home2.img} alt="" /> 
              <span className='title'>{Home2.title}</span>
              <span className='time'>{Home2.create_time}</span>
          </div>
                </NavLink>
          
      </div>
          <Wujie ></Wujie>
          <Zuixin authorList={authorList}  ></Zuixin>
          {/* <Zuixin authorList={authorList}  ></Zuixin> */}
                   
      
      {/* 复制粘贴组件 */}
           <div className={all}>
        <EbookTil title={qikan.title} />
        <NavLink to={"/authordetail/"+b}>
          <ul>
        {qikan.list?.map((item:any) => (
          <li key={item.id}>
            <div className={authorImg}>
              <div ><img src={item.avatar_url} alt="" /></div>
              <dl>
                <dt>{item.name}</dt>
                <dd>{item.label}</dd>
              </dl>
            </div>
            <p>作品：{item.workTil}</p>

          </li>
        ))}
      </ul>
        </NavLink>
      
      </div>  


      <Haizi></Haizi>
          <Wujie ></Wujie>
          <Zuixin authorList={authorList}  ></Zuixin>
      <Haizi></Haizi>
      
           
      </div>
  )
}